﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MySql.Data.MySqlClient;
using System.Data;

namespace PTTPOS_Solution.DAL
{
    public static class Table_DA
    {
        public static DataTable ListTable = new DataTable();
        public static void GetListTable()
        {
            MySqlCommand com = new MySqlCommand("select * from tbltables where Status <> 2", Connection_PTTPOS.GetConnection());
            com.Connection.Open();
            MySqlDataAdapter da = new MySqlDataAdapter(com);
            ListTable.Clear();
            da.Fill(ListTable);
            com.Connection.Close();
        }

        public static void CancelTables(string id_table,string id_order)// Phương thức hủy bàn
        {
            Order_pro_DA.DeleteOrder_pro(id_order);
            MySqlCommand com = new MySqlCommand("Update tbltables set status=0 where id=@id", Connection_PTTPOS.GetConnection());
            com.Parameters.AddWithValue("@id", id_table);
            com.Connection.Open();
            com.ExecuteNonQuery();
            com.Connection.Close();
        }

        public static void updatetableWithstatus(string id, string status)
        {
            MySqlCommand com = new MySqlCommand("update tbltables set status= @status where id=@id", Connection_PTTPOS.GetConnection());
            com.Parameters.AddWithValue("@id", id);
            com.Parameters.AddWithValue("@status", status);
            com.Connection.Open();
            com.ExecuteNonQuery();
            com.Connection.Close();
        }

        public static void updatetable(int id)
        {
            MySqlCommand com = new MySqlCommand("update tbltables set status= 1 where id=@id", Connection_PTTPOS.GetConnection());
            com.Parameters.AddWithValue("@id", id);
            com.Connection.Open();
            com.ExecuteNonQuery();
            com.Connection.Close();
        }
    }
}
